home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CTOOLS10.ARJ / DLIST.H < prev    next >
C/C++ Source or Header  |  1991-12-31  |  3KB  |  111 lines

  1. /****************************************************************************
  2. *
  3. *                    Copyright (C) 1991 Kendall Bennett.
  4. *                            All rights reserved.
  5. *
  6. * Filename:        $RCSfile: dlist.h $
  7. * Version:        $Revision: 1.5 $
  8. *
  9. * Language:        ANSI C
  10. * Environment:    any
  11. *
  12. * Description:    Header file for doubly linked list routines.
  13. *
  14. * $Id: dlist.h 1.5 91/12/31 19:40:54 kjb Exp $
  15. *
  16. * Revision History:
  17. * -----------------
  18. *
  19. * $Log:    dlist.h $
  20. * Revision 1.5  91/12/31  19:40:54  kjb
  21. * Modified include files directories.
  22. * Revision 1.4  91/09/27  03:10:41  kjb
  23. * Added compatibility with C++.
  24. * Revision 1.3  91/09/26  10:07:16  kjb
  25. * Took out extern references
  26. * Revision 1.2  91/09/01  19:37:20  ROOT_DOS
  27. * Changed DLST_TAIL macro so that it returns a pointer to the REAL last
  28. * node of the list, not the dummy last node (l->z).
  29. * Revision 1.1  91/09/01  18:38:23  ROOT_DOS
  30. * Initial revision
  31. ****************************************************************************/
  32.  
  33. #ifndef    __DLIST_H
  34. #define    __DLIST_H
  35.  
  36. #ifndef    __DEBUG_H
  37. #include "debug.h"
  38. #endif
  39.  
  40. /*---------------------- Macros and type definitions ----------------------*/
  41.  
  42. typedef struct DLST_BUCKET {
  43.     struct DLST_BUCKET    *next;
  44.     struct DLST_BUCKET    *prev;
  45.     } DLST_BUCKET;
  46.  
  47. typedef struct {
  48.     int            count;            /* Number of elements currently in list    */
  49.     DLST_BUCKET    *head;            /* Pointer to head element of list        */
  50.     DLST_BUCKET    *z;                /* Pointer to last node of list            */
  51.     DLST_BUCKET    hz[2];            /* Space for head and z nodes            */
  52.     } DLIST;
  53.  
  54. /* Return a pointer to the user space given the address of the header of
  55.  * a node.
  56.  */
  57.  
  58. #define    DLST_USERSPACE(h)    ((void*)((DLST_BUCKET*)(h) + 1))
  59.  
  60. /* Return a pointer to the header of a node, given the address of the
  61.  * user space.
  62.  */
  63.  
  64. #define    DLST_HEADER(n)        ((DLST_BUCKET*)(n) - 1)
  65.  
  66. /* Return a pointer to the user space of the list's head node. This user
  67.  * space does not actually exist, but it is useful to be able to address
  68.  * it to enable insertion at the start of the list.
  69.  */
  70.  
  71. #define    DLST_HEAD(l)        DLST_USERSPACE((l)->head)
  72.  
  73. /* Return a pointer to the user space of the last node in list.    */
  74.  
  75. #define    DLST_TAIL(l)        DLST_USERSPACE((l)->z->prev)
  76.  
  77. /* Determine if a list is empty
  78.  */
  79.  
  80. #define    DLST_EMPTY(l)        ((l)->count == 0)
  81.  
  82. /*-------------------------- Function Prototypes --------------------------*/
  83.  
  84. #ifdef __cplusplus
  85. extern "C" {
  86. #endif
  87.  
  88. void *dlst_newnode(int size);
  89. void dlst_freenode(void *node);
  90. DLIST *dlst_init(void);
  91. void dlst_kill(DLIST *l,void (*freeNode)());
  92. void dlst_insertafter(DLIST *l,void *node,void *after);
  93. void *dlst_deletenext(DLIST *l,void *node);
  94. void *dlst_first(DLIST *l);
  95. void *dlst_last(DLIST *l);
  96. void *dlst_next(void *prev);
  97. void *dlst_prev(void *next);
  98. void dlst_mergesort(DLIST *l,int (*cmp_func)());
  99.  
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103.  
  104. #endif
  105.